<?php
	include_once('functions.php');
	require_once ('user.php');

	$email = $_POST["email"];
	$password = md5($_POST["senha"]);
	
	$connection = getdb();	
	$sql = pg_query($connection, "SELECT * FROM usuarios WHERE email = '" .$email."' AND encrypted_password = '".$password. "'");
	$users = pg_num_rows($sql);
	var_dump($users);
	if($users < 1){
		session_start();
		$_SESSION['error'] = "Usuários ou senha incorretos.";
		header("Location: /savua");
	}
	else{
		session_start();
		$_SESSION['email'] = $email;
		$_SESSION['password'] = $password;
		header("Location: /savua");
	}

	pg_close($connection);
?>